<template>
	<view>
		<text>这是我的页面</text>
		<view class="my">来来来</view>
		<view class="uni-title uni-common-pl">日期选择器</view>
		<view class="uni-list">
			<view class="uni-list-cell">
				<view class="uni-list-cell-left">
					当前选择
				</view>
				<view class="uni-list-cell-db">
					<picker mode="date" :value="date" :start="startDate" :end="endDate" @change="bindDateChange">
						<view class="uni-input">{{date}}</view>
					</picker>
				</view>
			</view>
		</view>
		<view>
			<uni-rate value="2"></uni-rate>
			<uni-rate size="18" value="5"></uni-rate>
			<uni-rate max="10" value="5"></uni-rate>
			<uni-rate disabled="true" value="3.5"></uni-rate>
		</view>
		<!-- #ifdef APP-PLUS -->
		<view class="pwd-wrap">
			<button type="primary" @tap="isZhiWen">是否支持指纹识别</button>
			<text>{{zhiwenText}}</text>
		</view>
		<view>
			<button type="primary" @tap="openSystem">弹出系统选择按钮框</button>
		</view>
		<view>
			<button type="primary" @click="getIDCard()">点击识别身份证</button>
		</view>
		<!-- #endif -->
	</view>
</template>

<script>
	// #ifdef APP-PLUS
	// const card = uni.requireNativePlugin('DC-CardRecognize');
	// #endif
	import uniRate from "@/components/uni-rate/uni-rate.vue"
	export default {
		data() {
			const currentDate = this.getDate({
				format: true
			})
			return {
				title: 'picker',
				array: ['中国', '美国', '巴西', '日本'],
				index: 0,
				date: currentDate,
				time: '12:01',
				zhiwenText: ''
			}
		},
		computed: {
			startDate() {
				return this.getDate('start');
			},
			endDate() {
				return this.getDate('end');
			}
		},
		components:{
			uniRate
		},
		methods: {
			getDate(type) {
				const date = new Date();
				let year = date.getFullYear();
				let month = date.getMonth() + 1;
				let day = date.getDate();

				if (type === 'start') {
					year = year - 60;
				} else if (type === 'end') {
					year = year + 3;
				}
				month = month > 9 ? month : '0' + month;;
				day = day > 9 ? day : '0' + day;
				return `${year}-${month}-${day}`;
			},
			// #ifdef APP-PLUS
			fingerprint: function() {
				var waiting = null;
				plus.fingerprint.authenticate(function() {
					plus.nativeUI.closeWaiting(); //兼容Android平台关闭等待框
					plus.nativeUI.toast('指纹识别成功');
				}, function(e) {
					switch (e.code) {
						case e.AUTHENTICATE_MISMATCH:
							plus.nativeUI.toast('指纹匹配失败，请重新输入');
							break;
						case e.AUTHENTICATE_OVERLIMIT:
							plus.nativeUI.closeWaiting(); //兼容Android平台关闭等待框
							plus.nativeUI.toast('指纹识别失败次数超出限制，请使用其它方式进行认证');
							break;
						default:
							plus.nativeUI.closeWaiting(); //兼容Android平台关闭等待框
							plus.nativeUI.toast('指纹识别失败(' + e.code + ')，请重试');
							break;
					}
				});
				// Android平台弹出等待提示框 
				if ('Android' == plus.os.name) {
					plus.nativeUI.showWaiting('请开始指纹识别...');
				}
			},
			isZhiWen() {
				// 检查是否支持指纹识别
				if (plus.fingerprint) {
					if (!plus.fingerprint.isSupport()) {
						this.zhiwenText = '此设备不支持指纹识别';
						return;
					}
					if (!plus.fingerprint.isKeyguardSecure()) {
						this.zhiwenText = '此设备未设置密码锁屏，无法使用指纹识别';
						return;
					}
					if (!plus.fingerprint.isEnrolledFingerprints()) {
						this.zhiwenText = '此设备未录入指纹，请到设置中开启';
						return;
					}
					this.zhiwenText = '此设备支持指纹识别';
					this.fingerprint();
				} else {
					this.zhiwenText = '当前环境不支持指纹识别API，请更新到最新版本';
				}
			},
			openSystem() {
				plus.nativeUI.actionSheet({
					title: "Plus is ready!",
					cancel: "取消",
					buttons: [{
						title: "1"
					}, {
						title: "2"
					}]
				}, function(e) {
					console.log("User pressed: " + e.index);
				});
			},
			getIDCard() {
                // card.startRecognize({
                //     maskType:"IDCardBack"
                // },result => {
                //     console.log(JSON.stringify(result));
                // });
            },
			// #endif
			bindDateChange: function(e) {
				this.date = e.target.value
			},

		}
	}
</script>

<style lang="scss">
	
</style>
